<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/8
 * Time: 16:08
 */
class RequestCdn  extends MY_Controller{
    public function __construct()
    {
        parent::__construct();
    }

  public function download(){
        try{ 
			$this->load->library('RedisHandle');
            $this->load->library('Tool');	
            $this->load->helper('func');
            $this->load->database();	     
			$this->load->library('session');
			$this->load->model('User_model','user');
            $params['merCode'] = $_GET['merCode'];
            $params['time'] = $_GET['time'];
            $params['sign'] = $_GET['sign'];
            $params['vid'] =$_GET['vid'];
            $params['muid'] = $_GET['muid'];
		
            $param['floder'] = urldecode($_GET['floder']);
			if($param['floder']==''){
				$param['floder']=$params['merCode'];
			}
	    //var_dump($param);die();
            //必填参数验证
            mustParams($params);
				
           
                if($params['vid']==''|| $params['muid']==''){
                    json_exit(10004,'缺少参数');
                }
				
                $redis = RedisHandle::getInstance();
                $key = RedisHandle::getKey($params['vid']);
								
                $file_name = $redis->get($key);
				
                if($file_name==''){
                    $sql = "SELECT filename FROM file_information WHERE vid=".$params['vid'];
                    $query = $this->db->query($sql);
                    $row = $query->row();
                    $file_name = $row->filename;
                }
				
                if($param['floder']==''){
                    $url =  $this->config->item('base_url').$params['merCode'].'/'.$file_name;//没有分类自动取商户分类
					$file_path = FCPATH.'uploads/'.$params['merCode']."/".$file_name;

                }else{
                    $url = $this->config->item('base_url').$param['floder'].'/'.$file_name;
					$file_path = FCPATH.'uploads/'.$param['floder']."/".$file_name;

                }	
				
				$path='http://192.168.23.149:8080/uploads/'.$param['floder'].'/'.$file_name."?merCode=".$params['merCode']."&muid=".$params['muid']."&time=".$params['time']."&sign=".$params['sign'];//文件存放地址
				header("Location:$path");
				
									
				 
           
            RedisHandle::close();

         }catch(Exception $e){

        json_exit(10006,$e->getMessage());

         }      
    }
}
